/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013-2014 sagyf Yang. The Four Group.
 */

package app.events;

import app.events.stat.StatBusListener;
import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;

import java.util.concurrent.Executors;

/**
 * <p>
 * EventBus 总线处理.
 * </p>
 *
 * @author sagyf yang
 * @version 1.0 2014-05-12 12:29
 * @since JDK 1.6
 */
public class EventBusContext {
    public static final int ASYNC_THREAD_SIZE = 10;
    private static EventBus bus;

    private EventBusContext() {
    }

    protected static void init() {
        bus = new AsyncEventBus(Executors.newFixedThreadPool(ASYNC_THREAD_SIZE));
        bus.register(new EventBusListener());
        bus.register(new StatBusListener());
    }

    public static <E> void post(E event) {
        bus.post(event);
    }
}
